<template>
  <div class="app-container">
    <div class="app-container-flex systemSetting">
      <NewFullScreen
        v-model="showDialog"
        title=""
        :btn-list="fullInfo.btnList"
        :need-return="false"
      >
        <div class="model-panel">
          <div class="model-panel-title">
            <p>系统设置</p>
          </div>
          <div class="model-panel-body">
            <!-- form -->
            <page-form
              class="paddingBox order-model-formBox flex_wrap_start_start"
              v-model:ref-obj="formInfo.ref"
              :disabled="formInfo.disabled"
              :data="formInfo.data"
              :field-list="formInfo.systemFieldList"
              :rules="formInfo.rules"
              :label-width="formInfo.labelWidth"
            >
              <!-- <template v-slot:form-websocket_ip_port>
                <el-input
                  v-model="formInfo.data.websocket_ip_port"
                  style="width: 300px"
                  class="not-mongolia"
                  type="input"
                  placeholder="请输入webscoket链接地址"
                />
              </template> -->
              <template v-slot:form-system_name>
                <el-input
                  v-model="formInfo.data.system_name"
                  class="not-mongolia"
                  type="input"
                  placeholder="请输入系统名称"
                />
              </template>
            </page-form>
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>对接设置</p>
          </div>
          <div class="model-panel-body" style="padding: 0 2px">
            <el-tabs v-model="dockingSet.activeName">
              <el-tab-pane label="SLIP平台对接" name="platformInterconnection">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj.sync="dockingSet.platformInterconnectionRef"
                  :data="formInfo.data"
                  :field-list="dockingSet.fieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="HIS对接" name="dockingHis">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj.sync="dockingSet.hisFieldListRef"
                  :data="formInfo.data"
                  :field-list="dockingSet.hisFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="省采对接" name="province">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj.sync="dockingSet.provinceRef"
                  :data="formInfo.data"
                  :field-list="dockingSet.provinceList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="智能柜对接" name="smartCabinet">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj.sync="dockingSet.smartCabinetRef"
                  :data="formInfo.data"
                  :field-list="dockingSet.smartCabinetList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>基础管理设置</p>
          </div>
          <div class="model-panel-body" style="padding: 0 2px">
            <el-tabs v-model="baseManageSet.activeName">
              <el-tab-pane label="组织架构管理" name="organizationalStructure">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj.sync="consumablesTabs.organizationRef"
                  :data="formInfo.data"
                  :field-list="consumablesTabs.organizationList"
                  :rules="formInfo.rules"
                  :label-width="'208px'"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="合同管理设置" name="contractSetting">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj.sync="baseManageSet.contractSettingRef"
                  :data="formInfo.data"
                  :field-list="baseManageSet.contractFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>物资管理设置</p>
          </div>
          <div class="model-panel-body" style="padding: 0 2px">
            <el-tabs v-model="consumablesTabs.activeName">
              <el-tab-pane label="基础设置" name="base">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="consumablesTabs.baseRef"
                  :data="formInfo.data"
                  :field-list="consumablesTabs.baseFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="效期设置" name="validity">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="consumablesTabs.validityRef"
                  :data="formInfo.data"
                  :field-list="consumablesTabs.validityFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="精度设置" name="accuracy">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="consumablesTabs.accuracyRef"
                  :data="formInfo.data"
                  :field-list="consumablesTabs.accuracyFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                  @handleEvent="handleEvent"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="策略设置" name="strategy">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="consumablesTabs.strategyRef"
                  :data="formInfo.data"
                  :field-list="consumablesTabs.strategyFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="流程设置" name="process">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="consumablesTabs.processRef"
                  :data="formInfo.data"
                  :field-list="consumablesTabs.processFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="PDA流程设置" name=" pda_process">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="consumablesTabs.pdaProcessRef"
                  :data="formInfo.data"
                  :field-list="consumablesTabs.pdaProcessFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="跟台管理设置" name="with_operate_table">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="consumablesTabs.withOperateTableRef"
                  :data="formInfo.data"
                  :field-list="consumablesTabs.withOperateTableFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="寄售管理设置" name="consign_business">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="consumablesTabs.consignBusinessRef"
                  :data="formInfo.data"
                  :field-list="consumablesTabs.consignBusinessFieldList"
                  :rules="formInfo.rules"
                  :label-width="'208px'"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="暂估入库管理" name="estimation_stock">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="consumablesTabs.estimationStockRef"
                  :data="formInfo.data"
                  :field-list="consumablesTabs.estimationStockList"
                  :rules="formInfo.rules"
                  :label-width="'208px'"
                ></page-form>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>仓储上下架设置</p>
          </div>
          <div class="model-panel-body" style="padding: 0 2px">
            <el-tabs v-model="wmsTabs.activeName">
              <el-tab-pane label="上下架策略" name="wmsStrategy">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="wmsTabs.wmsStrategyRef"
                  :data="formInfo.data"
                  :field-list="wmsTabs.wmsStrategyFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="上架规则" name="rule">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="wmsTabs.wmsPutRuleRef"
                  :data="formInfo.data"
                  :field-list="wmsTabs.wmsPutRuleFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>资产管理设置</p>
          </div>
          <div class="model-panel-body" style="padding: 0 2px">
            <el-tabs v-model="assetTabs.activeName">
              <el-tab-pane label="精度设置" name="accuracy">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="assetTabs.accuracyRef"
                  :data="formInfo.data"
                  :field-list="assetTabs.accuracyFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="策略设置" name="strategyFieldList">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="assetTabs.strategyFieldListRef"
                  :data="formInfo.data"
                  :field-list="assetTabs.strategyFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="流程设置" name="process">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="assetTabs.processRef"
                  :data="formInfo.data"
                  :field-list="assetTabs.processFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
              <el-tab-pane label="维修设置" name="maintenance">
                <page-form
                  class="paddingBox order-model-formBox flex_wrap_start_start"
                  v-model:ref-obj="assetTabs.maintenanceRef"
                  :data="formInfo.data"
                  :field-list="assetTabs.maintenanceFieldList"
                  :rules="formInfo.rules"
                  :label-width="formInfo.labelWidth"
                ></page-form>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
      </NewFullScreen>
    </div>
  </div>
</template>

<script setup name="systemSetup">
import {
  batchUpdateCoreSystemConfig,
  getCoreSystemConfigAll,
} from '@/api/core.js'
const { proxy } = getCurrentInstance()

const showDialog = ref(true)
const formRefs = ref(null)
const fullInfo = ref({
  btnList: [{ label: '保存', event: save, show: true }],
})
// 对后端数据类型为字符串的提前转为数字类型，避免number框报错
const typeIsNumData = ref([
  'product_nearly_effective',
  'license_nearly_effective',
  'brand_permit',
  'expect_delivery_day',
  'qty_calc_precision',
  'qty_show_precision',
  'price_precision',
  'use_application_cron_time',
  'many_people_verification',
  'max_upload_picture',
  'max_file_size',
  'assets_price_precision',
  'measuring_instruments_warn_day',
  'medical_repair_warn_time',
  'not_medical_repair_warn_time',
])
const formInfo = ref({
  ref: null,
  data: {},
  fieldList: [],
  systemFieldList: [
    //系统设置
    {
      label: '系统名称',
      value: 'system_name',
      type: 'slot',
      show: false,
    },
    {
      label: '供应商端',
      value: 'enabled_supplier',
      type: 'select-model',
      code: 'enabled_type',
    },
    {
      label: '合同协同',
      value: 'is_contract_push_platform',
      type: 'select-model',
      code: 'default_no_or_yes',
      show: false,
    },
    {
      label: '登录异常账号锁定',
      value: 'abnormal_lock',
      type: 'select-model',
      clearable: false,
      code: 'yes_or_no',
    },
    {
      label: '登录异常次数(次)',
      value: 'abnormal_number',
      type: 'number',
      min: 1,
    },
    {
      label: '锁定时间(分钟)',
      value: 'abnormal_lock_time',
      type: 'number',
      min: 1,
    },
    {
      label: '登录验证码校验',
      value: 'login_verification_code',
      type: 'select-model',
      clearable: false,
      code: 'yes_or_no',
    },
    {
      label: '登录异常几次出现验证码(次)',
      value: 'login_verification_code_time',
      type: 'number',
      min: 0,
    },
    {
      label: '强制修改初始密码',
      value: 'first_password_change',
      type: 'select-model',
      code: 'yes_or_no',
      clearable: false,
    },
    {
      label: '强制密码更换',
      labelTip:
        '强制密码更换，则用户登录后必须修改初始密码，非强制修改，用户可根据自己需要修改',
      value: 'forcing_password_change',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '密码更换周期(月)',
      value: 'password_change_period',
      type: 'number',
      min: 1,
    },
    {
      label: '密码强度要求',
      value: 'password_requirements',
      multiple: true,
      type: 'select-model',
      code: 'password_requirements',
    },
    {
      label: '最短密码长度(字符)',
      value: 'password_length',
      type: 'number',
      min: 6,
    },
    //会计期间设置
    {
      label: '自动切换物资会计期间',
      value: 'auto_switch_material_fiscal_period',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '图片单次最大上传数量',
      value: 'max_upload_picture',
      type: 'number',
      min: 1,
      max: 20,
      labelTip: '最大为20；当前生效范围：厂家、证照、供应商',
    },
    {
      label: '附件最大上传限制',
      value: 'max_file_size',
      type: 'number',
      min: 1,
      max: 200,
      labelTip: '最大为200MB',
    },
    {
      label: '消息是否声音提醒',
      value: 'message_notification_sounds',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '金额小数位自动补0',
      value: 'amount_supplement_0',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
    // {
    //   label: 'webscoket链接地址',
    //   value: 'websocket_ip_port',
    //   labelTip:
    //     'webscoket链接地址一‘ws://’开头，结尾处不能加‘/’,如：ws://127.0.0.1:8080',
    //   type: 'slot',
    //   show: false,
    //   className: 'not-br',
    // },
  ],
  rules: {
    // websocket_ip_port: [
    //   {
    //     required: true,
    //     message: '请输入webscoket链接地址',
    //     trigger: 'blur',
    //   },
    // ],
    abnormal_number: [
      { required: true, message: '请输入登录异常次数', trigger: 'blur' },
    ],
    abnormal_lock_time: [
      { required: true, message: '请输入锁定时间', trigger: 'blur' },
    ],
    login_verification_code_time: [
      {
        required: true,
        message: '请输入登录异常几次出现验证码',
        trigger: 'blur',
      },
    ],
    password_change_period: [
      { required: true, message: '请输入密码更换周期(月)', trigger: 'blur' },
    ],
    system_name: [
      { required: true, message: '请输入系统名称', trigger: 'blur' },
    ],
    product_nearly_effective: [
      { required: true, message: '请输入产品近效期', trigger: 'blur' },
    ],
    measuring_instruments_warn_day: [
      {
        required: true,
        message: '请输入计量器具检定预警天数',
        trigger: 'blur',
      },
    ],
    asset_warranty_warn_day: [
      {
        required: true,
        message: '请输入资产维保预警天数',
        trigger: 'blur',
      },
    ],
    license_nearly_effective: [
      { required: true, message: '请输入证照近效期', trigger: 'blur' },
    ],
    brand_permit: [
      {
        required: true,
        message: '请输入厂家资质近效期',
        trigger: 'blur',
      },
    ],
    purch_order_expire: [
      {
        required: true,
        message: '请输入采购单过期天数',
        trigger: 'blur',
      },
    ],
    password_length: [
      { required: true, message: '请输入最短密码长度', trigger: 'blur' },
    ],
    qty_calc_precision: [
      { required: true, message: '请输入数量计算精度', trigger: 'blur' },
    ],
    qty_show_precision: [
      { required: true, message: '请输入数量展示精度', trigger: 'blur' },
    ],
    price_precision: [
      { required: true, message: '请输入价格精度', trigger: 'blur' },
    ],
    assets_price_precision: [
      { required: true, message: '请输入金额精度', trigger: 'blur' },
    ],
    max_upload_picture: [
      {
        required: true,
        message: '请输入最大上传图片数量',
        trigger: 'blur',
      },
    ],
    max_file_size: [
      {
        required: true,
        message: '请输入最大上传限制',
        trigger: 'blur',
      },
    ],
    product_contract_permit: [
      {
        required: true,
        message: '请输入耗材合同近效期',
        trigger: 'blur',
      },
    ],
    assets_contract_permit: [
      {
        required: true,
        message: '请输入资产合同近效期',
        trigger: 'blur',
      },
    ],
  },
  labelWidth: '190px',
})
const dockingSet = ref({
  platformInterconnectionRef: null,
  hisFieldListRef: null,
  provinceRef: null,
  smartCabinetRef: null,
  activeName: 'platformInterconnection',
  fieldList: [
    {
      label: '对接平台',
      labelTip:
        '系统设置选择了对接平台，则采购终止策略只能是供应商友好，收货拒收策略只能是重下采购单，保留策略只能是四舍五入',
      value: 'connect_platform',
      type: 'select-model',
      code: 'yes_or_no',
    },

    {
      label: '发票协同',
      labelTip: '是否推送入库单及消耗单信息到平台',
      value: 'receipt_together_config',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '合同协同',
      value: 'is_contract_push_platform',
      type: 'select-model',
      code: 'default_no_or_yes',
      show: false,
    },
    {
      label: '是否启用平台供应商端',
      labelTip: '只对资产业务有效',
      value: 'enabled_platform_supplier',
      type: 'select-model',
      disabled: false,
      code: 'yes_or_no',
    },
    {
      label: '待审核产品审批策略',
      value: 'allow_slip_product_check_approval',
      type: 'select-model',
      code: 'audit_type',
      show: false,
      onlyShowOption: ['1', '2'],
    },
    {
      label: '待审核机构审批策略',
      value: 'allow_slip_org_check_approval',
      type: 'select-model',
      code: 'audit_type',
      show: false,
      onlyShowOption: ['1', '2'],
    },
    {
      label: '待审核证照审批策略',
      value: 'allow_slip_license_check_approval',
      type: 'select-model',
      code: 'audit_type',
      show: false,
      onlyShowOption: ['1', '2'],
    },
    {
      label: '待审核厂家审批策略',
      value: 'allow_slip_brand_check_approval',
      type: 'select-model',
      code: 'audit_type',
      show: false,
      onlyShowOption: ['1', '2'],
    },
    {
      label: '供应商可维护字段',
      value: 'allow_supplier_fill_product_fields',
      multiple: true,
      type: 'select-model',
      code: 'allow_supplier_fill_product_fields',
    },
    {
      label: '是否隐藏临时入库',
      value: 'is_hidden_estimation_stock',
      type: 'select-model',
      disabled: false,
      code: 'yes_or_no',
    },
    // {
    //   label: '重点监控高值医用耗材',
    //   // labelTip: '字段是否必填',
    //   value: 'is_need_important_high_material',
    //   type: 'select-model',
    //   disabled: false,
    //   code: 'default_no_or_yes',
    // },
  ],
  hisFieldList: [
    {
      label: '是否对接his系统',
      value: 'connect_his',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '循环解冻HIS锁定数据（天）',
      value: 'his_unlock_with_day',
      type: 'number',
      min: 1,
    },
    {
      label: '循环拉取HIS计费数据（小时）',
      value: 'his_pull_data_with_hour',
      type: 'number',
      min: 1,
    },
  ],
  provinceList: [
    {
      label: '是否对接省采平台',
      value: 'connect_purchase_platform',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '对接省采平台',
      value: 'connect_purchase_platform_system',
      type: 'select-model',
      show: false,
      code: 'province_platform',
    },
    {
      label: '本地产品是否校验挂网信息',
      value: 'local_products_validate_network_info',
      type: 'select-model',
      show: false,
      code: 'yes_or_no',
    },
    {
      label: '是否根据省采供应商价目表自动调价',
      value: 'is_auto_update_supplier_product_price',
      type: 'select-model',
      show: false,
      code: 'default_no_or_yes',
    },
  ],
  smartCabinetList: [
    {
      label: '是否强制填写RFID码',
      value: 'force_fill_in_rfid',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
    {
      label: '是否支持打印RFID条码',
      value: 'force_print_in_rfid',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
  ],
})
const baseManageSet = ref({
  contractSettingRef: null,
  activeName: 'organizationalStructure',
  contractFieldList: [
    {
      label: '耗材合同近效期(天)',
      value: 'product_contract_permit',
      type: 'number',
    },
    {
      label: '资产合同近效期(天)',
      value: 'assets_contract_permit',
      type: 'number',
    },
  ],
})
const consumablesTabs = ref({
  activeName: 'base',
  baseRef: null,
  validityRef: null,
  accuracyRef: null,
  strategyRef: null,
  processRef: null,
  pdaProcessRef: null,
  withOperateTableRef: null,
  consignBusinessRef: null,
  uploadRef: null,
  estimationStockRef: null,
  organizationRef: null,

  baseFieldList: [
    //基础设置
    {
      label: '条码支持类型',
      value: 'code_type_support',
      multiple: true,
      type: 'select-model',
      code: 'code_type',
      className: 'code_type_support_name',
    },
    {
      label: '数量操作模式',
      value: 'qty_operate_mode',
      type: 'select-model',
      multiple: true,
      code: 'qty_operate_mode',
    },
    {
      label: '财务科目是否必填',
      value: 'is_need_financial_account',
      type: 'select-model',
      code: 'yes_or_no',
    },
  ],
  validityFieldList: [
    //效期设置
    {
      label: '产品近效期(天)',
      value: 'product_nearly_effective',
      type: 'number',
    },
    {
      label: '证照近效期(天)',
      value: 'license_nearly_effective',
      type: 'number',
    },
    {
      label: '厂家资质近效期(天)',
      value: 'brand_permit',
      type: 'number',
    },
    {
      label: '供应商预期到货天数(天)',
      value: 'expect_delivery_day',
      type: 'number',
    },
    {
      label: '最优效期提醒',
      value: 'optimal_validate',
      type: 'select-model',
      code: 'yes_or_no',
      labelTip:
        '领用管理-领用审核-生成出库单-选择库存后提交的时候<br/>' +
        '移库单-新增-保存的时候<br/>' +
        '消耗登记-消耗的时候<br/>',
    },
    {
      label: '发货是否强制校验产品证照日期',
      value: 'is_check_product_licence_date',
      type: 'select-model',
      disabled: false,
      code: 'default_no_or_yes',
    },
    {
      label: '是否校验证照失效日期',
      value: 'is_check_license_end_time',
      type: 'select-model',
      disabled: false,
      code: 'default_no_or_yes',
    },
    // {
    //   label: "耗材合同近效期(天)",
    //   value: "product_contract_permit",
    //   type: "number",
    // },
    // {
    //   label: "资产合同近效期(天)",
    //   value: "assets_contract_permit",
    //   type: "number",
    // },
  ],
  accuracyFieldList: [
    //精度设置
    {
      label: '数量计算精度',
      value: 'qty_calc_precision',
      type: 'number',
      event: 'qty_calc_precision',
      min: 0,
      max: 11,
    },
    {
      label: '数量展示精度',
      value: 'qty_show_precision',
      type: 'number',
      event: 'qty_show_precision',
      min: 0,
      max: 11,
    },
    {
      label: '价格精度',
      value: 'price_precision',
      type: 'number',
      min: 0,
      max: 11,
    },
    //精度只保留四舍五入,隐藏不允许设置
    {
      label: '数量计算精度保留策略',
      value: 'qty_calc_retention_strategy',
      type: 'select-model',
      event: 'qty_calc_retention_strategy',
      code: 'precision_retention_strategy',
      show: false,
    },
    {
      label: '数量展示精度保留策略',
      value: 'qty_show_retention_strategy',
      type: 'select-model',
      event: 'qty_show_retention_strategy',
      code: 'precision_retention_strategy',
      show: false,
    },
    {
      label: '价格精度保留策略',
      value: 'price_retention_strategy',
      type: 'select-model',
      code: 'precision_retention_strategy',
      show: false,
    },
  ],
  strategyFieldList: [
    //策略设置
    {
      label: '采购单中止策略',
      value: 'stop_strategy',
      type: 'select-model',
      code: 'stop_strategy',
    },
    {
      label: '收货拒收策略',
      value: 'receive_refuse_type',
      type: 'select-model',
      code: 'receive_refuse_type',
    },
    // {
    //   label: "不合格产品是否允许入库",
    //   value: "unqualified_product_store",
    //   type: "select-model",
    //   code: "yes_or_no",
    // },
    {
      label: '是否允许过期产品出库',
      value: 'allow_expire_out',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '申领量能否大于库存量',
      value: 'allow_use_qty_greater_stock',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '是否领用出库并入库',
      value: 'allow_use_export_and_store',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '领用是否定时入库',
      value: 'use_application_cron_stock',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '领用定时入库时间(天)',
      value: 'use_application_cron_time',
      type: 'number',
      min: 0,
      labelTip:
        '示例： <br/>' +
        '如果填写3，则表示自动入库更新时间为三天前的待入库状态的领用入库单<br/>',
    },
    {
      label: '多人验证',
      value: 'many_people_verification',
      type: 'number',
      min: 0,
      max: 10,
      labelTip:
        '示例： <br/>' +
        '如果填写0，则表示耗材收货无需验证直接可以收货<br/>' +
        '如果填写3，则表示耗材收货需要3人输入账号密码验证,验证通过后才能收货<br/>' +
        '目前最大值为10<br/>',
    },
    //{
    //  label: "扫码切换弹窗提示保存",
    //  value: "individual_scan_chang",
    //  type: "select-model",
    //  code: "default_yes_or_no"
    //}
    {
      label: '默认收货仓库',
      value: 'default_receive_depot',
      type: 'select-model',
      code: 'default_receive_depot',
      labelTip:
        '默认收货仓库：是系统统一默认的收货仓库 <br/>' +
        '部门默认仓库：是根据人员所在部门的默认仓库<br/>',
    },
    {
      label: '产品价格是否可以为0',
      value: 'product_price_can_be_zero',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '是否强制退货',
      value: 'mandatory_return',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '申领转申采购是否数量限制',
      value: 'use_convert_count_restrict',
      type: 'select-model',
      code: 'yes_or_no',
    },
    // {
    //   label: '入库单是否颜色区分',
    //   value: 'receiving_switch_color',
    //   type: 'select-model',
    //   code: 'yes_or_no',
    // },
    {
      label: '采购依据',
      value: 'purch_according',
      type: 'select-model',
      multiple: true,
      code: 'purch_according',
    },
    {
      label: '是否允许过期产品入库',
      value: 'allow_expired_store',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '是否允许批号输入特殊字符',
      value: 'check_batch_number_regex',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '供应商拒绝采购是否允许再次采购',
      value: 'supplier_refuse_purch_again',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '无码产品是否区分来源单号',
      value: 'none_distinct_store_batch_numer',
      type: 'select-model',
      code: 'yes_or_no',
      labelTip:
        '若区分来源单号则出库时产品将根据来源单号拆分 <br/>' +
        '若不区分则无法对无码产品做库龄分析<br/>',
    },
    {
      label: '是否允许平台供应商发货高于采购价',
      value: 'allowe_above_purchase_price',
      type: 'select-model',
      code: 'is_allow',
    },
    {
      label: '收货是否校验平台与默认供应商价格',
      value: 'receiving_verify_different_supplier_price',
      type: 'select-model',
      code: 'yes_or_no',
      labelTip:
        '平台发货单价与耗材供应商默认单价匹配：<br/>' +
        '如果不同则通过颜色区分出来，并且在保存时通过弹窗提示<br/>',
    },
    {
      label: '领用申请部门产品生效策略',
      value: 'use_application_dept_product_strategy',
      type: 'select-model',
      code: 'use_application_dept_product_strategy',
    },
    {
      label: '领用申请引用模板生效策略',
      value: 'use_application_template_strategy',
      type: 'select-model',
      code: 'use_application_template_strategy',
    },
    {
      label: '领入仓库是否必填',
      value: 'use_application_store_depot_required_strategy',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '领出仓库是否必填',
      value: 'use_application_export_depot_required_strategy',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '领用审核查看权限',
      value: 'use_application_audit_auth_type',
      type: 'select-model',
      code: 'dept_or_depot_type',
    },
    {
      label: '领用审核方式',
      value: 'use_application_audit_way',
      type: 'select-model',
      code: 'use_application_audit_way',
    },
    {
      label: '领用申请查看权限',
      value: 'use_application_auth_type',
      type: 'select-model',
      code: 'dept_or_depot_type',
    },
    {
      label: '产品带量预警天数',
      value: 'band_quantity_product_warn_day',
      type: 'number',
      min: -1,
      max: 9999,
      labelTip: '设置为0:当天提醒，设置为-1:不会提醒',
    },
    {
      label: '收费产品医保信息是否必填',
      value: 'is_need_medical_insurance',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '收费产品强制非以领定销',
      value: 'is_need_acquisition_replace_consume',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '入库自动生成调价单',
      value: 'store_auto_create_adjust',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '领用退回审核后自动出入库',
      value: 'use_application_return_auto_store',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
    {
      label: '领用退回是否强制关联领用入库单',
      value: 'use_application_return_import_store_order',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
    {
      label: '收货单是否更新发货单价格',
      value: 'receive_update_deliver_price',
      type: 'select-model',
      code: 'yes_or_no',
    },
  ],
  processFieldList: [
    //流程设置
    {
      label: '是否申购审批',
      value: 'allow_purch_application_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '是否申购复核',
      value: 'allow_purch_application_re_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '采购审批策略',
      value: 'allow_purch_order_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '是否领用审批',
      value: 'allow_use_application_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },

    {
      label: '寄售消耗确认是否审批',
      value: 'allow_consign_consume_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '寄售消耗确认是否复核',
      value: 'allow_consign_consume_re_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '耗材收货是否审核',
      value: 'material_receiving_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '移库是否审核',
      value: 'move_stock_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '调价单审批策略',
      value: 'adjust_price_order_approval_type',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '产品入院审批策略',
      value: 'allow_product_in_hospital_approval',
      type: 'select-model',
      code: 'audit_type',
      onlyShowOption: ['1', '2'],
    },
    {
      label: '采购计划审批策略',
      value: 'allow_purch_plan_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '报废出库审批策略',
      value: 'allow_scrap_export_approval',
      type: 'select-model',
      code: 'scrap_export_audit_type',
    },
  ],
  estimationStockList: [
    {
      label: '是否暂估入库',
      value: 'is_estimation_stock_business',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '暂估确认是否审批',
      value: 'allow_estimation_confirmation_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },
  ],
  organizationList: [
    {
      label: '人员供应商资源级联',
      value: 'user_supplier_cascade_resource',
      type: 'select-model',
      code: 'user_cascade_resource_strategy',
    },
    {
      label: '人员部门资源级联',
      value: 'user_dept_cascade_resource',
      type: 'select-model',
      code: 'user_cascade_resource_strategy',
    },
    {
      label: '人员仓库资源级联',
      value: 'user_depot_cascade_resource',
      type: 'select-model',
      code: 'user_cascade_resource_strategy',
    },
  ],

  pdaProcessFieldList: [
    //PDA流程设置
    {
      label: '是否领用出库并入库',
      value: 'pda_allow_use_export_and_store',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '是否报废并出库',
      value: 'pda_allow_scrap_and_export',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '收货方式',
      value: 'pda_receiving_type',
      type: 'select-model',
      code: 'pda_receiving_type',
    },
    {
      label: '是否整单收货',
      value: 'pda_allow_whole_order_receipt',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '整单收货是否一键填充',
      value: 'pda_allow_one_click_fill',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '移库方式',
      value: 'pda_transfer_type',
      type: 'select-model',
      code: 'pda_transfer_type',
    },
    {
      label: '是否开启原厂码盘盈',
      value: 'pda_allow_original_factory_code_inventory_profit',
      type: 'select-model',
      code: 'yes_or_no',
    },
  ],
  withOperateTableFieldList: [
    //跟台管理设置
    {
      label: '跟台订单是否需要审核',
      value: 'with_operate_table_need_audit',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
    {
      label: '跟台发货单是否自动验收',
      value: 'with_operate_table_need_accept',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
    {
      label: '跟台发货单管理模式',
      value: 'with_operate_table_manage_mode',
      type: 'select-model',
      //disabled: true,
      code: 'with_operate_table_manage_mode',
    },
  ],
  consignBusinessFieldList: [
    //寄售管理设置
    {
      label: '允许供应商查看寄售库存',
      value: 'allow_supplier_view_consign_depot_stock',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
    {
      label: '寄售消耗是否自动生成采购销售发货单',
      value: 'consign_consume_auto_add_order',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
    {
      label: '寄售业务',
      value: 'is_consign_business',
      type: 'select-model',
      code: 'new_enabled_type',
    },
    {
      label: '寄售消耗后是否自动生成寄售确认单',
      value: 'auto_consign_confirm',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
    {
      label: '已领定消产品是否自动生成寄售确认单',
      value: 'receive_consume_auto_consign_confirm',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
    {
      label: '消耗确认默认价格配置',
      value: 'consign_consume_confirm_default_price',
      type: 'select-model',
      code: 'consign_consume_confirm_default_price',
    },
    {
      label: '寄售确认生成待开票明细类型',
      value: 'consign_pend_receipt_type',
      type: 'select-model',
      code: 'consign_pend_receipt_type',
    },
    {
      label: '寄售是否同步推送待开票',
      value: 'syn_pend_receipt_order',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
  ],
  uploadFieldList: [
    {
      label: '图片单次最大上传数量',
      value: 'max_upload_picture',
      type: 'number',
      min: 1,
      max: 20,
      labelTip: '最大为20；当前生效范围：厂家、证照、供应商',
    },
  ],
})

const wmsTabs = ref({
  activeName: 'wmsStrategy',
  wmsStrategyRef: null,
  wmsPutRuleRef: null,
  wmsStrategyFieldList: [
    {
      label: '上架策略',
      value: 'wms_put_strategy',
      type: 'select-model',
      code: 'wms_put_strategy',
    },
    {
      label: '下架策略',
      value: 'wms_down_strategy',
      type: 'select-model',
      code: 'wms_down_strategy',
    },
  ],
  wmsPutRuleFieldList: [
    {
      label: '寄售产品允许混放',
      value: 'is_consign_product_mixing',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '寄售同产品不同批号效期允许混放',
      value: 'is_consign_batch_expiry_date_mixing',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '寄售同产品不同供应商允许混放',
      value: 'is_consign_supplier_mixing',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '非寄售产品允许混放',
      value: 'is_not_consign_product_mixing',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '非寄售同产品不同批号效期允许混放',
      value: 'is_not_consign_batch_expiry_date_mixing',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '非寄售同产品不同供应商允许混放',
      value: 'is_not_consign_supplier_mixing',
      type: 'select-model',
      code: 'audit_type',
    },
  ],
})
const assetTabs = ref({
  activeName: 'accuracy',
  accuracyRef: null,
  processRef: null,
  maintenanceRef: null,
  strategyFieldListRef: null,
  accuracyFieldList: [
    //精度设置
    {
      label: '金额精度',
      value: 'assets_price_precision',
      type: 'number',
      min: 0,
      max: 11,
    },
    {
      label: '金额精度保留策略',
      value: 'assets_price_retention_strategy',
      type: 'select-model',
      code: 'precision_retention_strategy',
    },
  ],
  strategyFieldList: [
    //策略设置
    {
      label: '资产是否强制退货',
      value: 'asset_mandatory_return',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '是否自动建卡',
      value: 'auto_build_card',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '计量单位是否必填',
      value: 'asset_unit_necessarily',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '是否维保',
      labelTip: '新增资产卡片页面,是否维保初始值取该配置值',
      value: 'is_maintenance_strategy',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '是否财务资产',
      labelTip: '新增资产卡片页面,是否为财务资产初始值取该配置值',
      value: 'is_finance_asset_strategy',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '是否计量资产',
      labelTip: '新增资产卡片页面,是否为计量资产初始值取该配置值',
      value: 'is_metering_strategy',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '计量器具检定预警天数(天)',
      value: 'measuring_instruments_warn_day',
      labelTip: '计划检定日期提前设置天数发送预警消息',
      type: 'number',
    },
    {
      label: '资产维保预警天数(天)',
      value: 'asset_warranty_warn_day',
      labelTip: '资产维保到期天数发送预警消息',
      type: 'number',
    },
    {
      label: '报修评价仅自己',
      labelTip:
        '如为是，报修人是自己且有评价权限就可以评价。反之，则只要有评价权限就可以评价',
      value: 'repair_evaluation_only_oneself',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '资金项目价格控制',
      value: 'asset_project_type_valid',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '资产卡片权限范围',
      value: 'asset_card_auth_type',
      type: 'select-model',
      code: 'asset_card_auth_type',
    },
    {
      label: '维修完工说明是否必填',
      value: 'repair_complete_describe_required',
      type: 'select-model',
      code: 'default_no_or_yes',
    },
  ],
  processFieldList: [
    //流程设置
    // {
    //   label: '资产登记是否审批',
    //   value: 'allow_assets_register_approval',
    //   type: 'select-model',
    //   code: 'yes_or_no',
    // },
    {
      label: '未到折旧年限资产是否可处置',
      value: 'allow_not_limit_month_asset_deal',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '是否申购审批',
      value: 'allow_asset_purch_application_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '是否申购复核',
      value: 'allow_asset_purch_application_re_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '资产退货审批',
      value: 'allow_asset_return_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },
    {
      label: '资产退货复批',
      value: 'allow_asset_return_re_approval',
      type: 'select-model',
      code: 'yes_or_no',
    },
    // {
    //   label: '是否审核报修单',
    //   value: 'audit_repair_order',
    //   type: 'select-model',
    //   code: 'yes_or_no',
    // },
    {
      label: '资产调整审批策略',
      value: 'assets_adjust_audit_type',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '资产退库审批策略',
      value: 'asset_return_depot_audit_type',
      type: 'select-model',
      code: 'audit_type',
    },
    // {
    //   label: '资产退库复批',
    //   value: 'allow_asset_return_depot_re_approval',
    //   type: 'select-model',
    //   code: 'yes_or_no',
    // },
    // {
    //   label: '资产移库审批策略',
    //   value: 'allow_asset_move_depot_approval',
    //   type: 'select-model',
    //   code: 'audit_type',
    // },
    {
      label: '采购审批策略',
      value: 'allow_asset_purch_order_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '资产报修审批策略',
      value: 'allow_repair_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '资产卡片审批策略',
      value: 'assets_register_approval_type',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '资产入库审批策略',
      value: 'allow_assets_store_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '资产采购发票审批策略',
      value: 'allow_asset_purch_invoice_order_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '资产领用出库审批策略',
      value: 'allow_assets_use_export_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '资产处置审批策略',
      value: 'allow_assets_deal_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '资产转移审批策略',
      value: 'allow_assets_transfer_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '资产移库审批策略',
      value: 'allow_asset_move_depot_approval_type',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '资产付款审批策略',
      value: 'allow_asset_payment_order_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '委外维修审批策略',
      value: 'allow_entrust_maintenance_apply_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '不良事件上报审批策略',
      value: 'allow_asset_adverse_event_approval',
      type: 'select-model',
      code: 'audit_type',
    },
    {
      label: '设备试用审批策略',
      value: 'allow_assets_trial_approval',
      type: 'select-model',
      code: 'audit_type',
    },
  ],
  maintenanceFieldList: [
    //维修设置
    {
      label: '医疗设备默认报修预警时长(分钟)',
      value: 'medical_repair_warn_time',
      labelTip:
        '医疗设备报修后超过设置分钟调度人员仍未派单则系统将自动通知调度员派单',
      type: 'number',
    },
    {
      label: '非医疗设备默认报修预警时长(分钟)',
      value: 'not_medical_repair_warn_time',
      labelTip:
        '非医疗设备报修后超过设置分钟调度人员仍未派单则系统将自动通知调度员派单',
      type: 'number',
    },
  ],
})
watch(
  () => formInfo.value.data.abnormal_lock,
  (val) => {
    console.log(val)
    formInfo.value.systemFieldList.map((item) => {
      if (['abnormal_number', 'abnormal_lock_time'].includes(item.value)) {
        item.required = Number(val) === 1
        item.show = Number(val) === 1
      }
    })
    Object.keys(formInfo.value.rules).forEach((key) => {
      if (['abnormal_number', 'abnormal_lock_time'].includes(key)) {
        formInfo.value.rules[key][0].required = Number(val) === 1
      }
    })
  },
  {
    immediate: true,
    deep: true,
  }
)
watch(
  () => formInfo.value.data.login_verification_code,
  (val) => {
    formInfo.value.systemFieldList.map((item) => {
      if (['login_verification_code_time'].includes(item.value)) {
        item.required = Number(val) === 1
        item.show = Number(val) === 1
      }
    })
    Object.keys(formInfo.value.rules).forEach((key) => {
      if (['login_verification_code_time'].includes(key)) {
        formInfo.value.rules[key][0].required = Number(val) === 1
      }
    })
  },
  {
    immediate: true,
    deep: true,
  }
)
watch(
  () => formInfo.value.data.forcing_password_change,
  (val) => {
    formInfo.value.systemFieldList.map((item) => {
      if (item.value === 'password_change_period')
        item.show = val == '1' ? true : false
    })
  },
  {
    immediate: true,
    deep: true,
  }
)
watch(
  () => formInfo.value.data.allow_purch_application_approval,
  (val) => {
    if (val == '1') {
      if (formInfo.value.data.allow_purch_application_re_approval === '-2') {
        formInfo.value.data.allow_purch_application_re_approval = '0'
      }
      showConsumablesTabsProcessFieldListItem(
        true,
        'allow_purch_application_re_approval'
      )
    } else {
      formInfo.value.data.allow_purch_application_re_approval = '-2'
      showConsumablesTabsProcessFieldListItem(
        false,
        'allow_purch_application_re_approval'
      )
    }
  },
  {
    immediate: true,
    deep: true,
  }
)
watch(
  () => formInfo.value.data.allow_asset_purch_application_approval,
  (val) => {
    if (val == '1') {
      if (
        formInfo.value.data.allow_asset_purch_application_re_approval === '-2'
      ) {
        formInfo.value.data.allow_asset_purch_application_re_approval = '0'
      }
      showAssetConsumablesTabsProcessFieldListItem(
        true,
        'allow_asset_purch_application_re_approval'
      )
    } else {
      formInfo.value.data.allow_asset_purch_application_re_approval = '-2'
      showAssetConsumablesTabsProcessFieldListItem(
        false,
        'allow_asset_purch_application_re_approval'
      )
    }
  },
  {
    immediate: true,
    deep: true,
  }
)

watch(
  () => formInfo.value.data.use_application_cron_stock,
  (val) => {
    let item = consumablesTabs.value.strategyFieldList.find(
      (item) => item.value === 'use_application_cron_time'
    )
    if (val == '1') {
      item.show = true
    } else {
      item.show = false
      formInfo.value.data.use_application_cron_time = 0
    }
  },
  {
    immediate: true,
  }
)

watch(
  () => formInfo.value.data.connect_platform,
  (val) => {
    if (val == '1') {
      formInfo.value.data.enabled_supplier = '0'
      setSysEnabledSupplierDisabled(true, 'enabled_supplier')
      showSystemFieldListItem(true, 'receipt_together_config')
      showSystemFieldListItem(true, 'is_contract_push_platform')
      setDockingSetDisabled(false, 'enabled_platform_supplier')
      showSystemFieldListItem(true, 'allow_slip_product_check_approval')
      showSystemFieldListItem(true, 'allow_slip_org_check_approval')
      showSystemFieldListItem(true, 'allow_slip_brand_check_approval')
      showSystemFieldListItem(true, 'allow_slip_license_check_approval')
    } else {
      setSysEnabledSupplierDisabled(false, 'enabled_supplier')
      formInfo.value.data.receipt_together_config = 0
      showSystemFieldListItem(false, 'receipt_together_config')
      showSystemFieldListItem(false, 'is_contract_push_platform')
      formInfo.value.data.is_contract_push_platform = '0'
      formInfo.value.data.enabled_platform_supplier = '0'
      setDockingSetDisabled(true, 'enabled_platform_supplier')
      showSystemFieldListItem(false, 'allow_slip_product_check_approval')
      showSystemFieldListItem(false, 'allow_slip_org_check_approval')
      showSystemFieldListItem(false, 'allow_slip_brand_check_approval')
      showSystemFieldListItem(false, 'allow_slip_license_check_approval')
    }
  },
  {
    immediate: true,
    deep: true,
  }
)

watch(
  () => formInfo.value.data.connect_purchase_platform,
  (val) => {
    if (val == '1') {
      showDockingSetProvinceListItem(true, 'connect_purchase_platform_system')
      showDockingSetProvinceListItem(
        true,
        'local_products_validate_network_info'
      )
      showDockingSetProvinceListItem(
        true,
        'is_auto_update_supplier_product_price'
      )
    } else {
      showDockingSetProvinceListItem(false, 'connect_purchase_platform_system')
      showDockingSetProvinceListItem(
        false,
        'local_products_validate_network_info'
      )
      showDockingSetProvinceListItem(
        false,
        'is_auto_update_supplier_product_price'
      )
      formInfo.value.data.connect_purchase_platform_system = 0
      formInfo.value.data.local_products_validate_network_info = 0
      formInfo.value.data.is_auto_update_supplier_product_price = 0
    }
  },
  {
    immediate: true,
    deep: true,
  }
)

watch(
  () => formInfo.value.data.is_consign_product_mixing,
  (val) => {
    if (val == '1') {
      formInfo.value.data.is_consign_batch_expiry_date_mixing = '-2'
      formInfo.value.data.is_consign_supplier_mixing = '-2'
      showWmsPutRuleFieldListItem(false, 'is_consign_batch_expiry_date_mixing')
      showWmsPutRuleFieldListItem(false, 'is_consign_supplier_mixing')
    } else {
      if (formInfo.value.data.is_consign_batch_expiry_date_mixing === '-2') {
        formInfo.value.data.is_consign_batch_expiry_date_mixing = '0'
      }

      if (formInfo.value.data.is_consign_supplier_mixing === '-2') {
        formInfo.value.data.is_consign_supplier_mixing = '0'
      }
      showWmsPutRuleFieldListItem(true, 'is_consign_batch_expiry_date_mixing')
      showWmsPutRuleFieldListItem(true, 'is_consign_supplier_mixing')
    }
  },
  {
    immediate: true,
    deep: true,
  }
)
watch(
  () => formInfo.value.data.is_not_consign_product_mixing,
  (val) => {
    if (val == '1') {
      formInfo.value.data.is_not_consign_batch_expiry_date_mixing = '-2'
      formInfo.value.data.is_not_consign_supplier_mixing = '-2'
      showWmsPutRuleFieldListItem(
        false,
        'is_not_consign_batch_expiry_date_mixing'
      )
      showWmsPutRuleFieldListItem(false, 'is_not_consign_supplier_mixing')
    } else {
      if (
        formInfo.value.data.is_not_consign_batch_expiry_date_mixing === '-2'
      ) {
        formInfo.value.data.is_not_consign_batch_expiry_date_mixing = '0'
      }

      if (formInfo.value.data.is_not_consign_supplier_mixing === '-2') {
        formInfo.value.data.is_not_consign_supplier_mixing = '0'
      }
      showWmsPutRuleFieldListItem(
        true,
        'is_not_consign_batch_expiry_date_mixing'
      )
      showWmsPutRuleFieldListItem(true, 'is_not_consign_supplier_mixing')
    }
  },
  {
    immediate: true,
    deep: true,
  }
)

onMounted(() => {
  getValueList()
  setData()
})

function setData() {
  formRefs.value = [
    formInfo.value.ref,
    dockingSet.platformInterconnectionRef,
    dockingSet.hisFieldListRef,
    dockingSet.provinceRef,
    dockingSet.smartCabinetRef,
    baseManageSet.contractSettingRef,
    assetTabs.value.processRef,
    assetTabs.value.maintenanceRef,
    assetTabs.value.accuracyRef,
    assetTabs.value.strategyFieldListRef,
    consumablesTabs.value.baseRef,
    consumablesTabs.value.validityRef,
    consumablesTabs.value.accuracyRef,
    consumablesTabs.value.strategyRef,
    consumablesTabs.value.processRef,
  ]
  formInfo.value.systemFieldList.forEach((item) => {
    // if (
    //   proxy.$store.state.user.userInfo.user.id == -1 &&
    //   item.value === 'websocket_ip_port'
    // ) {
    //   item.show = true
    // }
    if (
      proxy.$store.state.user.userInfo.user.id == -1 &&
      item.value === 'system_name'
    ) {
      item.show = true
    }
  })
}
function showSystemFieldListItem(show, nameValue) {
  let fieldList = dockingSet.value.fieldList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.show = show
    }
  })
}
function showConsumablesTabsProcessFieldListItem(show, nameValue) {
  let fieldList = consumablesTabs.value.processFieldList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.show = show
    }
  })
}
function showAssetConsumablesTabsProcessFieldListItem(show, nameValue) {
  let fieldList = assetTabs.value.processFieldList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.show = show
    }
  })
}
function showWmsPutRuleFieldListItem(show, nameValue) {
  let fieldList = wmsTabs.value.wmsPutRuleFieldList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.show = show
    }
  })
}
function showDockingSetProvinceListItem(show, nameValue) {
  let fieldList = dockingSet.value.provinceList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.show = show
    }
  })
}
function setSysEnabledSupplierDisabled(show, nameValue) {
  let fieldList = formInfo.value.systemFieldList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.disabled = show
    }
  })
}
function setDockingSetDisabled(disabled, nameValue) {
  let fieldList = dockingSet.value.fieldList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.disabled = disabled
    }
  })
}
function handleEvent(e, val) {
  let data = formInfo.value.data
  if (e === 'qty_calc_precision') {
    data.qty_show_precision = data.qty_calc_precision
  } else if (e === 'qty_show_precision') {
    data.qty_calc_precision = data.qty_show_precision
  } else if (e === 'qty_calc_retention_strategy') {
    data.qty_show_retention_strategy = val
  } else if (e === 'qty_show_retention_strategy') {
    data.qty_calc_retention_strategy = val
  }
}
function getValueList() {
  getCoreSystemConfigAll().then((resp) => {
    if (resp && resp.success) {
      const data = {}
      resp.data.forEach((item) => {
        if (typeIsNumData.value.indexOf(item.systemConfigCode) !== -1) {
          item.value = Number(item.value)
        }
        data[item.systemConfigCode] = item.value
      })
      formInfo.value.data = data
    }
  })
}
function save() {
  proxy.$fn.checkForm(formRefs.value).then(() => {
    if (saveRule()) return
    let arr = [
      ...formInfo.value.systemFieldList,
      ...dockingSet.value.fieldList,
      ...dockingSet.value.hisFieldList,
      ...dockingSet.value.provinceList,
      ...dockingSet.value.smartCabinetList,
      ...baseManageSet.value.contractFieldList,
      //...fiscalPeriodTabs.fieldList,
      ...consumablesTabs.value.baseFieldList,
      ...consumablesTabs.value.validityFieldList,
      ...consumablesTabs.value.accuracyFieldList,
      ...consumablesTabs.value.strategyFieldList,
      ...consumablesTabs.value.processFieldList,
      ...consumablesTabs.value.pdaProcessFieldList,
      ...consumablesTabs.value.withOperateTableFieldList,
      ...consumablesTabs.value.consignBusinessFieldList,
      ...consumablesTabs.value.uploadFieldList,
      ...consumablesTabs.value.estimationStockList,
      ...consumablesTabs.value.organizationList,
      ...wmsTabs.value.wmsStrategyFieldList,
      ...wmsTabs.value.wmsPutRuleFieldList,
      ...assetTabs.value.accuracyFieldList,
      ...assetTabs.value.strategyFieldList,
      ...assetTabs.value.processFieldList,
    ]
    const data = []
    for (let key in formInfo.value.data) {
      let item = arr.find((item) => item.value === key)
      data.push({
        systemConfigCode: key,
        value: formInfo.value.data[key],
        systemConfigName: item ? item.label : '',
      })
    }
    batchUpdateCoreSystemConfig(data).then(() => {
      proxy.$store.dispatch('permission/getCoreSystemConfig')
    })
  })
}
function saveRule() {
  let data = formInfo.value.data
  if (data.connect_platform === '1') {
    if (data.receive_refuse_type !== '1') {
      proxy.$message({
        message: `系统设置选择了对接平台，则收货拒收策略只能是重下采购单`,
        type: 'warning',
        duration: 3500,
        showClose: true,
      })
      return true
    }
    if (
      data.qty_calc_retention_strategy !== '2' ||
      data.qty_show_retention_strategy !== '2' ||
      data.price_retention_strategy !== '2'
    ) {
      proxy.$message({
        message: `系统设置选择了对接平台，则精度保留策略只能是四舍五入`,
        type: 'warning',
        duration: 3500,
        showClose: true,
      })
      return true
    }
  }
  if (
    data.use_application_cron_stock !== '0' &&
    data.use_application_cron_time < 1
  ) {
    proxy.$message({
      message: `开启了领用定时入库开关，则领用定时入库时间应大于0`,
      type: 'warning',
      duration: 3500,
      showClose: true,
    })
    return true
  }
  return false
}
</script>
<style lang="scss">
.code_type_support_name {
  .el-form-item__content {
    min-width: 130px !important;
  }
}
</style>
<style scoped lang="scss">
// :deep(.box-scroll-y) {
//   height: calc(100% - 40px);
// }
:deep(.el-select__tags) {
  flex-wrap: noWrap !important;
  overflow: hidden !important;
}
:deep(.el-tabs__content) {
  padding-top: 4px;
}
.model-panel,
.fullModel {
  border: none;
}
:deep(.layui-card-header) {
  border-bottom: 0 !important;
}
:deep(.el-tabs__nav-wrap::after) {
  height: 1px !important;
}
</style>
